package com.ltmall.api.news;

import com.ltmall.api.bean.News;
import com.ltmall.api.manager.NewsManager;

public class NewsCenter {
    /*
     * 1：生成存储数据库
     * 2：添加消息通知
     */

    public static int serverID = 1000000;

    public static void news(int userID, int typeA, String typeB, String title, String content, String picture, String param, NewsManager newsManager, boolean sendNewsTag) {
        int newsID = addNews(userID, typeA, typeB, title, content, picture, param, newsManager);
        if (sendNewsTag) {
            sendNews(userID, title, newsID, typeA);
        }
    }

    /**
     * 先插入消息数据库
     *
     * @param userID
     * @param typeA
     * @param typeB
     * @param title
     * @param content
     * @param picture
     * @param param
     * @param newsManager
     * @return
     */
    public static int addNews(int userID, int typeA, String typeB, String title, String content, String picture, String param, NewsManager newsManager) {
        News news = new News();
        news.setUserID(userID);
        news.setTypeA(typeA);
        news.setTypeB(typeB);
        news.setTitle(title);
        news.setContent(content);
        news.setPicture(picture);
        news.setRead(0);
        news.setParam(param);
        newsManager.addNews(news);
        return news.getNewsID();
    }

    public void test() {
        int userID = 1000653;
        String message = "我的消息";
        int newsID = 100;
        int typeA = 1;
        sendNews(userID, message, newsID, typeA);
    }

    //再次发送消息
    public static void sendNews(int userID, String message, int newsID, int typeA) {
        int fromUserID = serverID;
        int toUserID = userID;
        //HXNews.sendNews(fromUserID, toUserID, message, typeA, newsID);
    }
}
